package com.huike.web.controller.report;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import com.huike.common.core.domain.AjaxResult;
import com.huike.report.service.IReportService;

import java.time.LocalDate;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/index")
public class IndexController {

    @Autowired
    private IReportService reportService;


    /**
     * 首页--基础数据统计
     * @param beginCreateTime
     * @param endCreateTime
     * @return
     */
    @GetMapping("/getBaseInfo")
    public AjaxResult getBaseInfo(@RequestParam("beginCreateTime") String beginCreateTime,
                                  @RequestParam("endCreateTime") String endCreateTime){
        return AjaxResult.success(reportService.getBaseInfo(beginCreateTime,endCreateTime));
    }

    /**
     * 获取今天的信息
     * @return
     */
    @GetMapping("/getTodayInfo")
    public AjaxResult getTodayInfo(){
       Map<String,Integer> map =  reportService.getTodayInfo();
        return AjaxResult.success(map);
    }

    @GetMapping("/businessChangeStatistics")
    public AjaxResult businessChangeStatistics(
            @DateTimeFormat(pattern = "yyyy-MM-dd")  LocalDate beginCreateTime,
            @DateTimeFormat(pattern = "yyyy-MM-dd")  LocalDate endCreateTime
    ){
        List<Map<String,Object>> list = reportService.businessChangeStatistics(beginCreateTime,endCreateTime);
        return AjaxResult.success(list);
    }


    @GetMapping("/salesStatistic")
    public AjaxResult salesStatistic(
            @DateTimeFormat(pattern = "yyyy-MM-dd")  LocalDate beginCreateTime,
            @DateTimeFormat(pattern = "yyyy-MM-dd")  LocalDate endCreateTime
    ){
        List<Map<String,Object>> list = reportService.salesStatistic(beginCreateTime,endCreateTime);
        return AjaxResult.success(list);
    }

}